<?php
/**
 * related_artists.php
 *
 * INPUT: 	$_REQUEST['user1']
 * 			$_REQUEST['user2']
 * OUTPUT: 	an XML file with related artists.
 *
 * Speaks for its own I hope.
 * 
 * By Laurens Van Keer
 */
require 'auth.php';

header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>' . PHP_EOL;
echo '<Artists>' . PHP_EOL;

$apiClass = new lastfmApi();
$tasteClass = $apiClass->getPackage($auth, 'tasteometer', $config);

if ( empty($_REQUEST['user1']) || empty($_REQUEST['user2']) ) {
	die('<Error>No user specified!</Error>' . PHP_EOL . '</Artists>');
} else {

	// get usernames
	$user1 = htmlentities($_REQUEST['user1']);
	$user2 = htmlentities($_REQUEST['user2']);
	$methodVars = array(
		1 => array('type' => "user", 'value' => $user1), 
		2 => array('type' => "user", 'value' => $user2));

	$result = $tasteClass->compare($methodVars);	

	foreach($result['artists'] as $artist) {
	
		echo '<Artist>' . PHP_EOL;
			echo '<Name>' . htmlentities($artist['name']) . '</Name>' . PHP_EOL;
			echo '<Url>' . htmlentities($artist['url']) . '</Url>' . PHP_EOL;
			echo '<Thumbnail_small>' . htmlentities($artist['image']['small']) . '</Thumbnail_small>' . PHP_EOL;
			echo '<Thumbnail_medium>' . htmlentities($artist['image']['medium']) . '</Thumbnail_medium>' . PHP_EOL;
			echo '<Thumbnail_large>' . htmlentities($artist['image']['large']) . '</Thumbnail_large>' . PHP_EOL;
		echo '</Artist>' . PHP_EOL;
		
	}

}

echo '</Artists>' . PHP_EOL;
?>